/*
*    Qizx/open 3.0 beta
*
* This code is the open-source version of Qizx.
* Copyright (C) 2004-2009 Axyana Software -- All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License 
*  Version 1.1 (the "License"); you may not use this file except in 
*  compliance with the License. You may obtain a copy of the License at
*  http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
*  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
*  for the specific language governing rights and limitations under the
*  License.
*
* The Initial Developer of the Original Code is Xavier Franc - Axyana Software.
*
*/
using System;
namespace System.Qizx.Api.FullText
{
	
	/// <summary> Access to a thesaurus.</summary>
	/// <summary> Sequence of tokens. Used as an interface between thesauri and the FT
	/// engine.
	/// </summary>
	public class TokenSequence
	{
		private System.Collections.ArrayList tokens;
		
		public TokenSequence()
		{
			tokens = new System.Collections.ArrayList();
		}
		
		/// <summary> Returns the number of tokens in the sequence.</summary>
		public virtual int size()
		{
			return tokens.Count;
		}
		
		/// <summary> Returns the token at position 'index'.</summary>
		public virtual char[] getTokenAt(int index)
		{
			return (char[]) tokens[index];
		}
		
		/// <summary> Adds a token in last position.</summary>
		public virtual void  addToken(char[] token)
		{
			tokens.Add(token);
		}
		
		/// <summary> Removes tokens from positions index to index + count -1 inclusive. </summary>
		public virtual void  removeTokens(int index, int count)
		{
			for (int i = 0; i < count && tokens.Count > index; i++)
				tokens.RemoveAt(index);
		}
	}
	/// <summary> Structure returned by Thesaurus lookup.
	/// <p>
	/// Contains:<ul>
	/// <li>A list of token sequences, equivalent to the looked
	/// up sequence, 
	/// <li>the number of consumed input tokens (i.e the length of
	/// the recognized thesaurus entry).
	/// </ul>
	/// For example, if the thesaurus contains equivalences "wealthy",
	/// "well-off" and "well-to-do", then looking up the sequence "well off man"
	/// would return a LookupResult where consumedTokens = 2 (length of "well off"),
	/// and containing the token sequences "wealthy", "well off" and "well to do".
	/// </summary>
	public class LookupResult
	{
		protected internal int consumedTokens_Renamed_Field;
		private System.Collections.ArrayList tlists;
		
		/// <summary> Creates a new empty lookup result.</summary>
		/// <param name="consumedTokens">the number of consumed input tokens.
		/// </param>
		public LookupResult(int consumedTokens)
		{
			this.consumedTokens_Renamed_Field = consumedTokens;
			//this.tlists = new ArrayList();
		}
		
		/// <summary> Returns the number of consumed input tokens.</summary>
		public virtual int consumedTokens()
		{
			return consumedTokens_Renamed_Field;
		}
		
		/// <summary> Returns the number of equivalent word sequences.</summary>
		public virtual int size()
		{
			return tlists == null?0:tlists.Count;
		}
		
		/// <summary> Returns the word sequence at rank 'index'.</summary>
		public virtual TokenSequence getSequence(int index)
		{
			return (TokenSequence) tlists[index];
		}
		
		/// <summary> Appends a word sequence.</summary>
		public virtual void  addSequence(TokenSequence sequence)
		{
			if (tlists == null)
				tlists = new System.Collections.ArrayList();
			tlists.Add(sequence);
		}
	}
	public interface Thesaurus
	{
		/// <summary> Looks up a thesaurus for a sequence of tokens. Returns a list of
		/// replacement words or word sequences, and the number of tokens consumed
		/// (all this gathered in LookupResult type).
		/// <p>
		/// This method call can consume one or several input tokens, according to
		/// the thesaurus entry it recognizes. Therefore, the returned result also
		/// contains the number of consumed tokens. Replacement sequences may or may
		/// not contain the consumed sequence, this is left to the thesaurus
		/// implementation.
		/// <p>
		/// For example, if the thesaurus contains equivalences "wealthy",
		/// "well-off" and "well-to-do", then looking up the sequence "well off man"
		/// would return a LookupResult where consumedTokens = 2 (length of "well
		/// off"), and containing the token sequences "wealthy", "well off" and
		/// "well to do". (Note that the TextTokenizer is assumed here to cut on
		/// hyphens).
		/// </summary>
		/// <param name="tokens">sequence of source tokens. Each token is an array of
		/// characters rather than a string.
		/// </param>
		/// <returns> a list of replacement sequences. If no replacement is found in
		/// the thesaurus, null must be returned.
		/// </returns>
		LookupResult lookup(TokenSequence tokens);
		
	}
}